/*
 * pref.c
 *
 *  Created on: 2008-9-30
 *      Author: jiangxd
 */
#include <stdio.h>
#include <string.h>
#include "read.h"

const char path[40] = "/tmp/jreader.conf";

void pref_save() {
	FILE *fp = fopen(path,"w+");
	char buffer[256];
	if (fp != NULL) {
		snprintf(buffer,256,"%s\n",reader->fn);
		fputs(buffer,fp);
		snprintf(buffer,256,"%s\n",reader->font);
		fputs(buffer,fp);
		snprintf(buffer,256,"%s\n",reader->theme);
		fputs(buffer,fp);
		fclose(fp);
	}
}

void pref_load() {
	FILE *fp = fopen(path,"r");
	char ln[0x100];
	if (fp != NULL) {
		if (fgets(ln,0x100,fp) != NULL) {
			ln[strlen(ln) - 1] = '\0';
			strncpy(reader->fn,ln,0x100);
		}
		if (fgets(ln,0x100,fp) != NULL) {
			ln[strlen(ln) - 1] = '\0';
			strncpy(reader->font,ln,40);
		}
		if (fgets(ln,0x100,fp) != NULL) {
			ln[strlen(ln) - 1] = '\0';
			strncpy(reader->theme,ln,20);
		}
		fclose(fp);
	}
}
